/*
 * www.qwfys.org Inc.
 * Copyright (c) 2004-2017 All Rights Reserved.
 */
package org.qwfys.netty.core;

/**
 * Created by David on 2017/5/15.
 */

import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

@Sharable
public class SampleServerHandler extends ChannelInboundHandlerAdapter {
    static int nCount = 0;

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        System.out.println("Received message : "+ msg);
        ctx.write(msg);
        nCount++;
        System.out.println("nCount :"+ nCount);
//        if ((nCount % 50000) == 0){
//            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
//            System.out.println(nCount);
//        }
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.flush();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}
